package com.atguigu.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.bean.TravelItem;
import com.atguigu.dao.TravelItemMapper;
import com.atguigu.entity.PageResult;
import com.atguigu.entity.QueryPageBean;
import com.atguigu.service.TravelItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = TravelItemService.class)
@Transactional
public class TravelItemServiceImpl implements TravelItemService{

    @Autowired
    private TravelItemMapper travelItemMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<TravelItem> travelItemList = travelItemMapper.findPage(queryPageBean.getQueryString());
        PageInfo<TravelItem> pageInfo = new PageInfo<>(travelItemList);
        PageResult page = new PageResult(pageInfo.getTotal(),pageInfo.getList());
        return page;
    }

    @Override
    public List<TravelItem> findAll() {
        return travelItemMapper.findAll();
    }

    @Override
    public void deleteTravelItemById(Integer id) {
        travelItemMapper.deleteTravelItemById(id);
    }

    @Override
    public TravelItem echoById(Integer id) {
        return travelItemMapper.echoById(id);
    }

    @Override
    public void edit(TravelItem travelItem) {
        travelItemMapper.edit(travelItem);
    }

    @Override
    public void add(TravelItem travelItem) {
        travelItemMapper.add(travelItem);
    }
}
